import { ref } from 'vue'

export interface ApprovalProcess {
  id: number
  pId: number
  name: string
  remark: string
  postsId: string
  deptId: string
  activityId: string | null
  createdAt?: string
  updatedAt?: string
  children?: ApprovalProcess[]
  dept?: {
    name: string
  }
  posts?: {
    name: string
  }
}

interface AddParamOption {
  label: string
  value: any
}

interface AddParam {
  label: string
  prop: string
  component: string
  placeholder: string
  required?: boolean
  defaultValue?: any
  options?: AddParamOption[]
  colSpan?: number
  multiple?: boolean
  rules?: Array<{
    required?: boolean
    message: string
    trigger?: string
  }>
}

export const moduleApi = '/api/approvalProcess'
export const moduleName = '审批管理'

export const searchParams = [
  {
    label: '审批名称',
    prop: 'name',
    component: 'input',
    placeholder: '请输入审批名称',
  },
  {
    label: '部门',
    prop: 'deptId',
    component: 'TreeSelect',
    placeholder: '请选择部门',
  },
  {
    label: '职务',
    prop: 'postsId',
    component: 'DutySelect',
    placeholder: '请选择职务',
    multiple: false,
  },
]

export const addParams: AddParam[] = [
  {
    label: '上级审批',
    prop: 'pId',
    component: 'select',
    placeholder: '请选择上级审批',
    defaultValue: 0,
    options: [],
    colSpan: 24,
  },
  {
    label: '审批名称',
    prop: 'name',
    component: 'input',
    placeholder: '请输入审批名称',
    required: true,
    colSpan: 24,
    rules: [{ required: true, message: '请输入审批名称', trigger: 'blur' }],
  },
  {
    label: '部门',
    prop: 'deptId',
    component: 'TreeSelect',
    placeholder: '请选择部门',
    required: true,
    colSpan: 12,
    rules: [{ required: true, message: '请选择部门', trigger: 'change' }],
  },
  {
    label: '职务',
    prop: 'postsId',
    component: 'DutySelect',
    placeholder: '请选择职务',
    required: true,
    multiple: false,
    colSpan: 12,
    rules: [{ required: true, message: '请选择职务', trigger: 'change' }],
  },
  {
    label: '备注',
    prop: 'remark',
    component: 'textarea',
    placeholder: '请输入备注信息',
    colSpan: 24,
  },
]

interface TableColumn {
  label: string
  prop: string
  minWidth?: number
  fixed?: string
  component?: string
  noChecked?: boolean
  componentProps?: (row: any) => {
    buttons: Array<{
      text: string
      type: 'primary' | 'danger'
      link: boolean
      click: () => void
    }>
  }
}

export const tableColumns = ref<TableColumn[]>([
  {
    label: '审批名称',
    prop: 'name',
    minWidth: 180,
  },
  {
    label: '备注',
    prop: 'remark',
    minWidth: 200,
  },
  {
    label: '部门',
    prop: 'dept.name',
    minWidth: 150,
  },
  {
    label: '职务',
    prop: 'posts.name',
    minWidth: 150,
  },
  {
    label: '创建时间',
    prop: 'createdAt',
    minWidth: 180,
  },
  {
    label: '更新时间',
    prop: 'updatedAt',
    minWidth: 180,
  },
  {
    label: '操作',
    prop: 'operation',
    minWidth: 200,
    fixed: 'right',
    component: 'operation',
    noChecked: true,
  },
])
